package cn.gok.util;

import java.util.HashSet;
import java.util.Iterator;

/**
 * @ClassName HashSet的例子
 * @Description TODO
 * @Author HP
 * @Date 16:30 2022/7/8
 * @Version 1.0
 **/
public class HashSet的例子 {
    public static void main(String[] args) {
        HashSet的常用方法();
        HashSet的遍历();
    }


    private static void HashSet的遍历() {
        HashSet<String> set = new HashSet<>();
        set.add("aaaa");
        set.add("bbbb");
        set.add("cccc");
        set.add("dddd");
        set.add("eeee");
        for (String str:set){
            System.out.println(str);
        }
        System.out.println();

        Iterator<String > it = set.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        System.out.println();

            set.stream().forEach(System.out::println);
    }

    private static void HashSet的常用方法() {
        HashSet<String> hashSet = new HashSet<>();
        hashSet.add("asdasdasd");
        hashSet.add("sadasdasd");
        hashSet.add("asdasdasd");
        System.out.println(hashSet.size());
        hashSet.remove("asdasdasd");
    }
}
